<?php
session_start();
require_once('../model/userInfo.php');
require_once('../control/lookPage.php');
require_once('../control/timeAgo.php');
require_once('../model/artinfo.php');
require_once('../model/homeDao.php');
pdlook();
// var_dump($_SESSION);
$uName = $_SESSION['uName'];
showUserArticle($uName);
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户页面</title>
</head>
<link rel="stylesheet" href="../style/css/userIndex.css">
<script src="../style/js/jquery.min.js"></script>
<link rel="stylesheet" href="../style/css/font-face.css">
<!-- <link rel="stylesheet" href="../style/css/index.css"> -->
<link rel="stylesheet" href="../style/css/changeInfo.css">



<body>
    <div class="add-box">
        <!-- 头部 -->
        <div class="header">
            <a class="header-title" href="../view/index.php">说点吧</a>
            <?php
            if (isset($_SESSION['uName']) && trim($_SESSION['uName'] != '')) {
                $user = selectUser($_SESSION['uName']);
                echo <<<loginbefore
        <!-- 登录之后 -->
          <div class="user-logining">
            <img src="../image/avatar/$user[avatar]" alt="">
            <span>$user[uName]</span>
            <i class="iconfont icon-xiangxia1"></i>
          </div>
        loginbefore;
            } else {
                echo <<<loginafter
          <!-- 登录之前 -->
          <span class="header-login iconfont icon-morentouxiang">登录 / 注册</span>
        loginafter;
            }
            ?>

            <div class="user">
                <!-- 用户登录之后的下拉框 -->
                <ul>
                    <li><i class="iconfont icon-morentouxiang"></i><span>个人主页</span></li>
                    <li><i class="iconfont icon-xiugai"></i><span>修改信息...</span></li>
                    <hr>
                    <li class="user-out"><i class="iconfont icon-tuichu"></i><span>退出登录</span></li>
                </ul>
            </div>
        </div>
        <!-- 退出模态框 -->
        <div class="modal-out">
            <div class="modal-out-box">
                <div class="modal-out-box-msg">
                    <i class="iconfont icon-tuichu"></i>
                    <h2>退出登录</h2>
                    <span>确定要退出登录吗？</span>
                </div>
                <form action="../control/user.php" method="get">
                    <input type="hidden" name="action" value="out">
                    <button type="button">取消</button>
                    <input type="submit" value="退出登录">
                </form>
            </div>
        </div>
        <!-- 主要显示部分 -->
        <div class="center">

            <!-- 标题 -->
            <div class="center-title">
                <div style="">
                    我的文章
                </div>
            </div>
            <div class="center-article">
                <?php
                if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                    if (count($GLOBALS['UserArticleArr']) > 0) {
                        // var_dump($GLOBALS['UserArticleArr']);
                        foreach ($GLOBALS['UserArticleArr'] as $val) {
                            $artTimeP = timeAgo($val['published_time']);
                            echo <<<article
                  <div class="center-article-item" data-art="$val[article_id]">
                    <h3>$val[title]</h3>
                    <span class="list-item-board">$val[board_name]</span>

                    <div class="list-item-content">
                      $val[content]
                    </div>

                    <div class="list-item-zan">
                      <span><i class="iconfont icon-dianzan"></i>$val[like_count]</span>
                      <span><i class="iconfont icon-yanjing_xianshi"></i>$val[view_count]</span>
                    </div>

                    <div class="list-item-footer">
                   
                      <span><i class="iconfont icon-shizhong"></i>$artTimeP</span>
                      <div class="list-item-avatar"><img src="../image/avatar/$val[avatar]" alt=""
                          class="list-item-userImg"><span>$val[uName]</span></div>
                    </div>
                  </div>
                article;
                        }
                    } else {
                        echo "<div class='noArt'>您还没有发布文章，点击发布文章进行发布吧~</div>";
                    }
                }
                ?>

            </div>
            <div class="right">
                <div class="right-add">
                    <i class="iconfont icon-jia"></i>
                    <span>发表文章</span>
                </div>

            </div>
        </div>

        <!-- 文章主要内容 -->
        <div class="article">

            <?php
            if ($_SERVER['REQUEST_METHOD'] === "GET" && isset($_GET['aid'])) {
                $aid = trim($_GET['aid']);
                if (isset($_COOKIE['aid']) && $_COOKIE['aid'] != 'yes') {
                    if (isset($_COOKIE['user']) && trim($_COOKIE['user']) != '') {
                        viewCountAdd($aid);
                    }
                }
                byIdSelectArt($aid);
                byartSelectCom($aid);
                $info = $GLOBALS['art'];
                // var_dump($info);
                $cnum = count($GLOBALS['commont']);
                $rnum = count($GLOBALS['repArr']);
                $num = $cnum + $rnum;
                $time = $info['published_time'];
                $title = htmlspecialchars($info['title']);
                $content = htmlspecialchars($info['content']);
                $uName = htmlspecialchars($info['uName']);
                $avatar = htmlspecialchars($info['avatar']);
                $likeCount = intval($info['like_count']);
                $viewCount = intval($info['view_count']);

                echo <<<html1
                        <div class="box">

                            <div class="box-top">

                                <div class="box-top-logo">
                                    <i class="iconfont icon-wenjian"></i>
                                    <span>说点吧文章</span>
                                </div>

                                <div class="box-top-msg">
                                     <div class="box-top-left">
                                      
                                        <h3>$title</h3>
                    html1;
                if (isset($_SESSION['uid']) && isUserLike($_SESSION['uid'], $_GET['aid']) == 'yes') {
                    echo '<span class="box-top-dz" ><i class="iconfont icon-dianzan_kuai"></i>' . "<span>" . $likeCount . "</span>" . '</span>';
                } else {
                    echo '<span class="box-top-dz" ><i class="iconfont icon-dianzan"></i>' . "<span>" . $likeCount . "</span>" . '</span>';
                }


                echo <<<html2
                                    </div>

                                    <ul class="box-top-item">
                                        <li><i class="iconfont icon-yanjing_xianshi"></i> 浏览量 <span>$viewCount</span></li>
                                        <li><i class="iconfont icon-shizhong"></i> 发布于 <span>$time</span></li>
                                        <li><img src="../image/avatar/$avatar" alt=""><span>$uName</span></li>
                                    </ul>

                                </div>

                                <div class="box-top-line"></div>

                            </div>

                            <div class="box-content">
                                <span>文章内容：</span>
                                <p>$content</p>
                                <div class="box-content-line"></div>
                            </div>

                            <div class="box-reply">
                                <span>评论(<span>$num</span>)</span>
                html2;

                if (isset($_SESSION['uName']) && trim($_SESSION['uName']) != '') {
                    echo "<div class='box-reply-inp'>
                            <textarea cols='179' rows='5' maxlength='150' placeholder='发一条友善的评论吧~'></textarea>
                            <button class='sendbtn'><i class='iconfont icon-fasong'></i>发表评论</button>
                            <div class='textNum'><span class='wordCount'>0</span>/<span>150</span></div>
                          </div>";
                }
                echo " </div>";
                if (isset($_SESSION['uName']) && trim($_SESSION['uName']) != '') {
                    // 评论展示
                    if ($cnum > 0) {
                        echo '<ul class="user-parent-comment">';
                        foreach ($GLOBALS['CRArr'] as $val) {
                            $uname = htmlspecialchars($val['uName']);
                            $ctime = timeAgo($val['created_time']);
                            $comment = htmlspecialchars($val['content']);
                            $likes = intval($val['like_count']);
                            $cid = htmlspecialchars($val['comment_id']);
                            $whoid = htmlspecialchars($val['uid']);
                            echo <<<COMMENT
                                <li class="user-reply" data-cid="$cid" data-who="$whoid">
                                    <div class="user-reply-main">
                                        <div class="user-reply-top">
                                            <span>$uname</span>
                                            <span>$ctime</span>
                                        </div>
                                        <p>$comment</p>
                                        <div class="user-reply-footer">
                                            <span class="replySpan">回复</span>
                        COMMENT;
                            if (count($val['rep']) <= 0) {
                                echo "";
                            } else {
                                echo "<span class='shou'><i class='iconfont icon-xiangxia1'></i></span>";
                            }

                            if ($uname == $_COOKIE['user']) {
                                echo "<span class='delCom'>删除</span>";
                            }
                            echo <<<COMMENT2
                                        </div>
                                        <div class="user-reply-footer-com">
                                            <textarea cols="179" rows="5" maxlength="150" placeholder="发一条友善的评论吧~"></textarea>
                                            <button class="repBtn"><i class="iconfont icon-fasong"></i>回复</button>
                                            <div class="textNum"><span class="wordCount">0</span>/<span>150</span></div>
                                        </div>
                                    </div>
                        COMMENT2;

                            // 回复列表
                            if (isset($val['rep']) && is_array($val['rep'])) {
                                echo '<ul class="user-reply-son">';
                                // var_dump($val['rep']);
                                foreach ($val['rep'] as $rep) {
                                    $rname = htmlspecialchars($rep['uName']);
                                    $rid = htmlspecialchars($rep['reply_id']);
                                    $rtime = timeAgo($rep['created_time']);
                                    $rcomment = htmlspecialchars($rep['content']);
                                    $rlikes = intval($rep['like_count']);
                                    $who = homeSelectUser($rep['comment_who'])['uName'];
                                    $cid = htmlspecialchars($rep['comment_id']);
                                    $whoid = htmlspecialchars($rep['uid']);

                                    echo <<<REPLY
                                        <li class="son-reply" data-cid="$cid" data-who="$whoid" data-rid="$rid">
                                            <div class="son-reply-main">
                                                <div class="son-reply-top">
                                                    <span>$rname <span>:回复$who</span></span>
                                                    <span>$rtime</span>
                                                </div>
                                                <p>$rcomment</p>
                                                <div class="son-reply-footer">
                                                    <span>回复</span>


                        REPLY;

                                    if ($rname == $_COOKIE['user']) {
                                        echo "<span class='delRep'>删除</span>";
                                    }
                                    echo <<<REPLY1
                                          </div>
                                                <div class="son-reply-footer-com">
                                                    <textarea cols="179" rows="5" maxlength="150" placeholder="发一条友善的评论吧~"></textarea>
                                                    <button class="sonRepBtn"><i class="iconfont icon-fasong"></i>回复</button>
                                                    <div class="textNum"><span class="wordCount">0</span>/<span>150</span></div>
                                                </div>
                                            </div>
                                        </li>


                        REPLY1;
                                }
                                echo '</ul>';
                            }
                            echo '</li>';
                        }
                        echo "</ul><div class='tofooter'>到底了~</div>";
                    } else {
                        echo "<ul class='user-parent-comment'></ul>";
                        echo "</ul><div class='tofooter'>到底了~</div>";
                    }
                } else {
                    echo "<div class='noRep'>请先登录~</div>";
                }


                echo '</div>';
            }
            ?>
        </div>

        <!-- 个人信息修改 -->
        <div class="userInfoChange ">
            <div class="uInfo">
                <!-- 修改信息头部 -->
                <div class="uinfo_top">
                    <div class="top_left">
                        <i class="iconfont icon-morentouxiang"></i>
                        <span>修改用户信息</span>
                    </div>
                    <div class="top_rghit">
                        <i class="iconfont icon-cha"></i>
                    </div>
                </div>
                <!-- 修改信息切换 -->
                <div class="infoToggle">
                    <div class="toSpan">
                        <span class="uspanActive"><i class="iconfont icon-xiugaimima"></i>修改密码</span>
                        <span><i class="iconfont icon-xiugaitouxiang"></i>修改头像</span>
                    </div>
                    <div class="toLine"></div>
                    <div class="infoMain">
                        <!-- 修改密码 -->
                        <div class="infomm">
                            <span>当前密码*</span>
                            <input type="password" placeholder="输入当前的密码" class="oldmm">
                            <span>新密码*</span>
                            <input type="password" placeholder="输入新密码" class="newmm">
                            <span>确认密码*</span>
                            <input type="password" placeholder="确认密码" class="qrmm">
                        </div>
                        <!-- 修改头像 -->
                        <div class="infoAvater">
                            <div class="avatar">
                                <label for="avatar"><img src="../image/avatar/default.png" alt="点击添加头像"></label>
                            </div>
                            <input type="file" id="avatar1" accept="image/*" style="display: none;" name="avatar"
                                required>
                        </div>
                        <div class="infoButton">

                            <button><i class="iconfont icon-baocun"></i>保存</button>
                        </div>

                    </div>
                </div>
            </div>
        </div>

        <div class="dzErr"><span>请登录~</span><i class="iconfont icon-cha"></i></div>
        <div class="saveMsg"><span>保存成功~</span></div>
    </div>

</body>
<script src="../style/js/userIndex.js"></script>
<script src="../style/js/changeInfo.js"></script>
<script src="../style/js/delcom.js"></script>

</html>